<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<%@ include file="/jsp/common/commonUnusual.jsp"%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">

	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid(
				{
					nowrap : false,
					striped : true,
					collapsible : true,
					remoteSort : true,
					notSelectByRow : false,
					/* frozenColumns : [ [ {
						field : 'ids',
						checkbox : true
					} ] ], */
					toolbar : [
							],
					onLoadError : function() {
						$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
					},
					onClickRow :  function(rowIndex) {
									$(".myrad").prop("checked", false);
									$(".myrad").eq(rowIndex).prop("checked", true);
									$('#listDisplay').datagrid('beginEdit', rowIndex);
					            }
					}); 

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
		
	//编辑模块
	var editIndex = undefined;
	function onClickRow(index){
		if (editIndex != index){
			if (endEditing()){
				$('#listDisplay').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				editIndex = index;
			} else {
				$('#listDisplay').datagrid('selectRow', editIndex);
			}
		}
	}
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#listDisplay').datagrid('validateRow', editIndex)){
			var ed = $('#listDisplay').datagrid('getEditor', {index:editIndex,field:'level'});
			var levelname = $(ed.target).combobox('getText');
			$('#listDisplay').datagrid('getRows')[editIndex]['levelname'] = levelname;
			$('#listDisplay').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	
	//下拉框
    $(function() {        
        $('#unusualDeal').combobox({   
            url:"<c:url value='/unusual/pulldownUnusualDeal.do?space=0'/>",   
            editable:true, //不可编辑状态  
            cache: false,  
            panelHeight: '150',  
            valueField:'unusualDeal',     
            textField:'unusualDealName',                      
            }); 
    });
	//异常处理
    function unusauldealButton(){
		//校验
		if($('#unusualDeal').combobox('getValue') ==''){
			$.messager.alert("提示", "处理方式没有填写", 'info');
			return;
		}
		if($('#unusualDealDetailed').textbox('getValue') ==''){
            $.messager.alert("提示", "处理明细内容没有填写", 'info');
            return;
        }
        var row = $('#listDisplay').datagrid('getSelections');   
        if(row.length == 0){
            $.messager.alert('提示','请选择一条记录操作！','info');
            return;
        }else{
            //校验
            if(row[0]['unusualDealFlag'] != 0){
            	$.messager.alert('提示','该异常已经处理过。','info');
            	return;
            }
            
            //设值
            document.getElementsByName("ordIdForDeal")[0].value = row[0]['ordId'];
            document.getElementsByName("ordSupId")[0].value = row[0]['ordSupId'];
            document.getElementsByName("ordMaterId")[0].value = row[0]['ordMaterId'];
            document.getElementsByName("ordDate")[0].value = row[0]['ordDate'];
        }
		//提交处理
		if($('#unusualDeal').combobox('getValue') ==1){
			var new_win = window.open("<c:url value='/jsp/selectfood/selectMaterSelfForUnusual.jsp'/>","news","width=1200px,height=600px,status=no,scrollbars=yes");
	        new_win.focus();
		}else if($('#unusualDeal').combobox('getValue') ==2){
			var new_win = window.open("<c:url value='/jsp/selectfood/selectMaterConForUnusual.jsp'/>","news","width=1200px,height=600px,status=no,scrollbars=yes");
            new_win.focus();
		}else if($('#unusualDeal').combobox('getValue') ==3 ||$('#unusualDeal').combobox('getValue') ==4 ){
			$('#UnusualForm').form('submit',
		            {
		                url:'<c:url value='/unusual/UnusualDealForKeep.do'/>', //查询提交路径
		                onSubmit:function()//提交按钮相应函数
		                {
		                    
		                    return $('#UnusualForm').form('validate');
		                },
		                success:function(data){
		                    data = eval('(' + data + ')');
		                    if(data.success){
		                        $.messager.alert('系统提示', '处理成功。', 'info', function(){
		                            window.opener.window.tea();
		                            window.close();
		                        });
		                    }else{
		                        var message = "系统错误 ，处理失败。";
		                        $.messager.alert("提示", message, 'warning');
		                        
		                    }
		                },
		                error:function(){
		                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
		                    return;
		                }
		            }
			);
		}
        
    }
</script>
</head>

<body>
    <table>
    <tr><td>
    <form id="UnusualForm" name="UnusualForm" method="post"  >
        <div style="height: auto; width:1180px;background: #fafafa; padding: 2px;" class="easyui-panel" title="&nbsp&nbsp&nbsp&nbsp&nbsp异常处理操作"  
            collapsible="true" minimizable="false" maximizable="false" closable="false">
            <table cellpadding="5">
                <tr>
                    <td>处理方式</td>
                    <td>
                        <input class="easyui-combobox" name="unusualDeal" id="unusualDeal" editable="false" data-options="required:true"/> 
                    </td>
                </tr>
                <tr>
                    <td>处理明细内容</td>
                    <td>
                        <input class="easyui-textbox" name="unusualDealDetailed" id="unusualDealDetailed" editable="true" data-options="multiline:true,required:true" style="height:60px;width:300px" /> 
                    </td>
                </tr>
                <tr>
                    <td align="" colspan="2"> 
                        <input width="200px" type="button" onclick="unusauldealButton()" value="提交处理">
                    </td>
                </tr>
                <input class="easyui-validatebox" type="hidden" name="ordIdForDeal" id="ordIdForDeal"  />
                <input class="easyui-validatebox" type="hidden" name="ordSupId"  />
                <input class="easyui-validatebox" type="hidden" name="ordMaterId"  />
                <input class="easyui-validatebox" type="hidden" name="ordDate"  />
                <input class="easyui-validatebox" type="hidden" name="ordId" value="${ordId }" />                
            </table>
        </div>
    </form>
    </td></tr>
    <tr><td>
	<table id="listDisplay" title="材料订单列表" singleSelect=true
		iconCls="icon-list" idField="ordSupMaterId"
		url="<c:url value="/unusual/findUnusualDetailed.do?oid=${ordId }&supId=${supId }"/>"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="false" pageSize="20"
		pageList="[10,20,30,40,50,100,150]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
				<tr>
				    <th field="id" width="25" align="center"  checkbox="true" >
					</th> 
					<th field="oid" width="80"  sortable="true" hidden="true">
                        oid
                    </th>
					<th field="ordSupMaterId" width="80"  sortable="true" hidden="true">
						ID
					</th>
				    <th field="ordId" width="60"  sortable="true" >
						订单ID
					</th>	
 					<th field="ordCustId" width="60" sortable="true" hidden ="true" hidden ='true'>
						客户ID
					</th>
					<th field="ordCustName" width="80" sortable="true" >
						客户名
					</th>
					<th field="ordSupId" width="60" sortable="true" hidden ="true" >
						供货商ID
					</th>	
					<th field="ordSupName" width="80" sortable="true" >
						供货商名
					</th>	
					<th field="ordDate" width="80" sortable="true" >订单日期
                    </th>   
					<th field="ordMaterId" width="60" sortable="true" >
						材料id
					</th>
					<th field="ordMaterName" width="100"  sortable="true" >
						材料名
					</th>
					<th field="ordMaterLevel" width="50"  sortable="true"  formatter="formatFoodType" hidden="true" >
						品级
					</th>
                    <th field="brands" width="60" sortable="true" >品牌
                    </th>
                    <th field="specifications" width="60" sortable="true" >规格
                    </th>
					<th field="ordMaterWeight" width="100"  sortable="true" >
						需求材料数量
					</th>
					<th field="ordMaterValue" width="100"  sortable="true"  hidden="true">
						需求材料价格
					</th>
					<th field="storeWeight" width="60"  sortable="true" hidden='true'>
						材料库存
					</th>	
					<th field="ordMaterWeightReal" width="100"  sortable="true"  >
						实际到货数量
					</th>	
					<th field="unit" width="60"  sortable="true" >单位
                    </th>  
					<th field="ordMaterValueReal" width="90"  sortable="true"  hidden="true">
						实际材料价格
					</th>
					<th field="unusualRemark" width="150"  sortable="true" >异常说明
                    </th>
                    <th field="unusualDealFlag" width="60" formatter="formateUnusualDealFlag" sortable="true" >是否处理
                    </th>
                    <th field="unusualDeal" width="150"  sortable="true"  formatter="formaterUnusualDeal">处理方式
                    </th>
                    <th field="selfOrdId" width="80"  sortable="true">关联订单id
                    </th>
                    <th field="unusualDealDetailed" width="150"  sortable="true" >处理原因明细
                    </th>
 				</tr>
		</thead>
	</table>
	</td></tr>
	</table>
</body>
</html>